#include <Ogre.h>
#include <OIS/OIS.h>
using namespace Ogre;

#include "MarbleMax.h"

void Marble_Max::destroyScene()
{
	mSceneMgr->destroyAllAnimations();				// destroy all animations in the scene
	mSceneMgr->destroyAllAnimationStates();			// destroy all animation states in the scene
	mSceneMgr->destroyAllBillboardChains();			// destroy all billboard chains
	mSceneMgr->destroyAllBillboardSets();			// destroy all billboard sets
	mSceneMgr->destroyAllCameras();					// destroy all cameras
	mSceneMgr->destroyAllEntities();				// destroy all entities in the scene
	mSceneMgr->destroyAllInstancedGeometry();		// destroy all instanced geometry
	mSceneMgr->destroyAllLights();					// destroy all lights
	mSceneMgr->destroyAllManualObjects();			// destroy all custom objects in the scene
	mSceneMgr->destroyAllMovableObjects();			// destroy all movable objects in the scene
	mSceneMgr->destroyAllParticleSystems();			// destroy all particle systems in the scene
	mSceneMgr->destroyAllRibbonTrails();			// destroy all ribbon trails in the scene
	mSceneMgr->destroyAllStaticGeometry();			// destroy all static geometry in the scene
}
bool Marble_Max::frameStarted(const FrameEvent& evt)
{
	if(mWindow->isClosed())					// if the window is destroyed, stop rendering
		return false;
	switch(currGameState)					// switch between play state and menu state
	{
	case ROLLSTATE:							// if play state is activated
		return Marble_Max::rollState(evt);	// go through the play state's frame
		break;
	case MENUSTATE:							// if menu state is activated
		return Marble_Max::menuState(evt);	// go through the menu state's frame
		break;
	case BUILDSTATE:						// if build state is activated
		return Marble_Max::buildState(evt);	// go through the build state's frame
		break;
	default:								// if none is activated, there is an error and
		return false;						// it needs to be killed, so return false
	}
	return true;
}
bool Marble_Max::frameEnded(const FrameEvent& evt)
{
	if(currGameState == ROLLSTATE)			// if play state is activated
	{
		statCFPS->setCaption("Current FPS: " + StringConverter::toString(mWindow->getLastFPS())); // get the current fps
		statAFPS->setCaption("Average FPS: " + StringConverter::toString(mWindow->getAverageFPS())); // get the average fps
		statDbg->setCaption(mDebugString);	// get the debug string
	}
	if(currGameState == BUILDSTATE)
	{
		statCFPS->setCaption("Current FPS: " + StringConverter::toString(mWindow->getLastFPS())); // get the current fps
		statAFPS->setCaption("Average FPS: " + StringConverter::toString(mWindow->getAverageFPS())); // get the average fps
		statLoc->setCaption("Current Location: " + StringConverter::toString(camNode->getPosition()));
		statDbg->setCaption(mDebugString);	// get the debug string
	}
	return true;
}
bool Marble_Max::switchState(Game_State gs)
{
	switch(gs)					// switch between play state and menu state
	{
	case ROLLSTATE:							// if play state is activated
		mSceneMgr = Root::getSingletonPtr()->getSceneManager("GameManager");	// get the play scene manager
		mainView->setCamera(mCamera);											// set the camera to be the play scene's camera
		break;
	case MENUSTATE:
		mSceneMgr = Root::getSingletonPtr()->getSceneManager("GUIMenu");	// get the play scene manager
		mainView->setCamera(menuCam);										// set the camera to be the play scene's camera
		break;
	case BUILDSTATE:
		break;
	default:
		return false;
		break;
	}
	return true;
}